package com.example.compose

import android.app.Application
import android.content.Context
import coil.ImageLoader
import coil.ImageLoaderFactory
import com.example.compose.util.NetworkUtils
import dagger.hilt.android.HiltAndroidApp

/**
 * Created by Android Studio.
 * User: HuangWeiQiang
 * Date: 2021/4/22
 * Time: 16:54
 */
@HiltAndroidApp
class App : Application(), ImageLoaderFactory {
    companion object {
        lateinit var appContext: Context
    }

    override fun onCreate() {
        super.onCreate()
        appContext = this
    }

    /**
     * 不使用默认,自己建一个单例,ImageLoaderFactory自动延迟初始化
     * memoryCachePolicy 设置默认的内存缓存策略
     * **/
    override fun newImageLoader(): ImageLoader {
        return ImageLoader.Builder(applicationContext)
            .okHttpClient {
                NetworkUtils.okHttpClient
            }
            .build()
    }
}